#银行自动存取机
#定义用户列表变量
account_infos = [{"account_No":"00001","pwd":"11111","balance":"100"},
                 {"account_No":"00002","pwd":"22222","balance":"500"},
                 {"account_No":"00003","pwd":"33333","balance":"3466"}]

#检查登录是否正确
def login(account_infos):
    yourNo = input("请输入账号：")
    yourPwd = input("请输入密码：")
    your_account = {}
    for account in account_infos:
        if yourNo == account['account_No']:
            count = 0
            while count<=2:
                if yourPwd == account["pwd"]:
                    print("您好，欢迎光临！")
                    your_account = account
                    break
                else:
                    count += 1
                    if count == 3:
                        print("您已连续三次输入错误密码，请联系银行工作人员！")
                    else:
                        print("密码输入错误，请重新输入！")
                        yourPwd = input("请重新输入密码：")
    return your_account

#查询当前账户余额
def check_balance(youraccount):
    print("您当前的余额为："+youraccount["balance"]+"元")
#取钱
def draw_money(youraccount,draw):
    if int(draw) > int(youraccount["balance"]):
        print("对不起，您当前余额不足")
        draw = input("请再次输入需要提取的金额：")
        draw_money(youraccount,draw)
    else:
        new_balance = int(youraccount["balance"]) - int(draw)
        youraccount["balance"] = str(new_balance)
        print("您本次提取了"+draw+"元")



#初始化界面

print("="*13,"欢迎使用银行存取一体机","="*13)
youraccount = login(account_infos)
if len(youraccount) > 0 :
    while True:
        print("{}{}".format("1、","查询余额"))
        print("{}{}".format("2、", "取钱"))
        print("{}{}".format("3、", "存钱"))
        print("{}{}".format("4、", "退出"))
        print("="*40)
        choice = input("请选择需要办理的业务:")
        if choice == "1":
            check_balance(youraccount)
            input("请输入回车键继续：")
        elif choice == "2":
            draw = input("请输入需要提取的金额：")
            draw_money(youraccount,draw)
            check_balance(youraccount)
            input("请输入回车键继续：")
        elif choice == "3":
            deposit = input("请输入存入的金额：")
            new_balance = int(youraccount["balance"])+int(deposit)
            youraccount["balance"] = str(new_balance)
            print("您本次提取了"+deposit+"元")
            check_balance(youraccount)
            input("请输入回车键继续：")
        elif choice == "4":
            print("="*13,"感谢使用！！！","="*13)
            break
else:
    print("退出系统")



